package cn.kgc.service;

import cn.kgc.mapper.UserMapper;
import cn.kgc.pojo.Role;
import cn.kgc.pojo.User;
import cn.kgc.util.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 蒿雨
 * @create 2021-11-02 19:53
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public User getLogin(String userCode, String userPassword) {
        return userMapper.getLogin(userCode, userPassword);
    }

    @Override
    public int getCount(Map<String, Object> map) {
        return userMapper.getCount(map);
    }


    @Override
    public PageBean<User> getUsers(Map<String, Object> map) {
        PageBean<User> userPageBean = new PageBean<>();
        userPageBean.setPageSize((int) map.get("pageSize"));
        userPageBean.setCurrentPage((int) map.get("index"));
        userPageBean.setTotalCount(getCount(map));
        map.put("startIndex", userPageBean.getStartIndex());
        userPageBean.setResult(userMapper.USERS(map));
        return userPageBean;
    }

    @Override
    public List<Role> ROLES() {
        return userMapper.ROLES();
    }

    @Override
    public User getUserForUserCode(String userCode) {
        return userMapper.getUserForUserCode(userCode);
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public int userDel(int id) {

        return userMapper.userDel(id);
    }

    @Override
    public boolean isNull(int id) {
        if (userMapper.isNull(id) <= 0) {
            return true;
        }
        return false;

    }

    @Override
    public User getUserById(int id) {
        return userMapper.getUserById(id);
    }

    @Override
    public boolean userModify(User user) {
        if (userMapper.userModify(user)>0){
            return true;
        }
        return false;
    }

}
